﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Cistern.Modify;

namespace University.Workshop.Presentation.Cistern.Modify
{
    /// <summary>
    /// Interaction logic for PageSecondStepModifyCistern.xaml
    /// </summary>
    public partial class PageSecondStepModifyCisternView : Page, ISecondStepForModifyCistern
    {
        PresenterModifyCistern pInternal;
        PresenterModifySecondStep pModifySecondStep;
        public PageSecondStepModifyCisternView(PresenterModifyCistern pExternal)
        {
            pInternal = pExternal;
            InitializeComponent();
            pModifySecondStep = new PresenterModifySecondStep(this);
        }


        public void Update()
        {
            pModifySecondStep.UpdateData();
        }

        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifySystemMessage(value);
            }
        }

        public string ErrorMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifyErrorMessage(value);
            }
        }

        public void ChargeDataToBasic()
        {
            pModifySecondStep.ChargeDataCistern();
        }

        public void GoNextPage()
        {
            pInternal.GoStepTwo();
        }

        public void GoBackPage()
        {

        }

        public string Capacity
        {
            get
            {
                return capacityTxBx.Text;
            }
            set
            {
                capacityTxBx.Text = value;
            }
        }

        public string LicensePlate
        {
            get 
            {
                return LicensePlateTxBx.Text;
            }
            set 
            {
                LicensePlateTxBx.Text = value;
            }
        }

        public string PersonId
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        //validations

        private void capacityTxBx_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsDigit(ch));
            }
        }

        private void LicensePlateTxBx_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsLetterOrDigit(ch));
            }
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Registrar Cisterna";
        }
        //-----------------------

        public Model.Cistern CisternToModify
        {
            get;
            set;
        }
    }
}
